﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using log4net.Repository.Hierarchy;
using Matrix.MaKaYunShang.BLL;
using Matrix.MaKaYunShang.Model.Dto;

namespace Matrix.MaKaYunShang.MagWeb.Controllers
{
    [Authorization]
    [Matrix.MaKaYunShang.Model.Attributes.Skip]
    public class PayController : BaseController
    {
        /// <summary>
        /// 支付列表
        /// </summary>
        /// <returns></returns>
        public ActionResult List()
        {
            return View();
        }

        [HttpPost]
        [Matrix.MaKaYunShang.Model.Attributes.Skip]
        public JsonResult Listing(int draw, int start, int length, string whereStr)
        {
            try
            {
                int order;
                int.TryParse(Request["order[0][column]"], out order);
                string direction = Request["order[0][dir]"];
                var orderByColumns = new[] { "Id", "LocalTransactionId", "WechatTransactionId", "PayPrice", "PayResult", "PayPlatformId", "AddTime" };
                string search = Request["search[value]"];

                TableDataViewDto<ViewPaymentRecordsDto> theList = PaymentRecordsBLL.Instance.GetPagingList(draw, (start / length) + 1, length, SqlSafe(search),
                    orderByColumns[order] + " " + direction);
                JsonResult jsonResult = Json(theList);
                jsonResult.MaxJsonLength = int.MaxValue;
                return jsonResult;
            }
            catch (Exception ex)
            {  
                Logger.Error("PayController  Listing Catch Error: " + ex.Message);
                return Json(false);
            }
        }
    }
}
